﻿using System;
using System.Collections.Generic;
using System.Transactions;
using Bingosoft.Data;
using HHMMS.WorkFlow.Model;

namespace HHMMS.WorkFlow.Service
{
	/// <summary>
	///表示对表WorkflowItem的所有操作的实现。
	/// </summary>
    public class WorkflowItemService
    {
        private readonly Dao dao = Dao.Get();

        private WorkflowItemService()
        { }

        private static WorkflowItemService instance = null;
        /// <summary>
        /// WorkflowItem服务类的单例。
        /// </summary>
        public static WorkflowItemService Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (typeof(WorkflowItemService))
                    {
                        instance = new WorkflowItemService();
                    }
                }
                return instance;
            }
        }

        public void Delete(string instanceId, int taskId)
        {
            this.dao.ExecuteNonQuery("workflow.workflowitem.delete", new
            {
                TaskId = taskId,
                InstanceId = instanceId
            });
        }

        public void Insert(WorkflowItem workflowItem)
        {
            this.dao.ExecuteNonQuery("workflow.workflowitem.insert", workflowItem);
        }

        public void Update(WorkflowItem workflowItem)
        {
            this.dao.ExecuteNonQuery("workflow.workflowitem.update", workflowItem);
        }

        public WorkflowItem Single(string instanceId, int taskId)
        {
            return this.dao.QueryEntity<WorkflowItem>("workflow.workflowitem.single", new
            {
                TaskId = taskId,
                InstanceId = instanceId
            });
        }

        public void SetReadTime(string instanceId, int taskId)
        {
            this.dao.ExecuteNonQuery("workflow.workflowitem.setreadtime", new
            {
                TaskId = taskId,
                InstanceId = instanceId
            });
        }


    }
}